package com.starbaba.utils;
//package com.ins.utils;
//
//import java.sql.PreparedStatement;
//import java.sql.SQLException;
//
//import javax.sql.DataSource;
//
//import com.base.common.database.BaseDao;
//import com.base.common.database.DBPoolManager;
//import com.base.common.database.DaoHelper;
//import com.mysql.jdbc.Connection;
//
//public class Test {
//
//    public static void main(String[] args) {
//
//        int batchSize = 1000;
//        int insertCount = 1000;
//
//        testDefault(batchSize, insertCount);
//        
//        testRewriteBatchedStatements(batchSize,insertCount);
//    }
//
//
//    private static void testDefault(int batchSize, int insertCount) throws SQLException {  
//        long start = System.currentTimeMillis();
//        doBatchedInsert(batchSize, insertCount,"");
//        long end = System.currentTimeMillis();
//        System.out.println("default:" + (end -start) + "ms");
//    }
//
//    private static void testRewriteBatchedStatements(int batchSize, int insertCount) throws SQLException {
//        long start = System.currentTimeMillis();
//        doBatchedInsert(batchSize, insertCount, "rewriteBatchedStatements=true");
//        long end = System.currentTimeMillis();
//        System.out.println("rewriteBatchedStatements:" + (end -start) + "ms");
//    }
//
//
//    private static void doBatchedInsert(int batchSize, int insertCount, String mysqlProperties) throws SQLException {
//        
//        //DruidDataSource dataSource = new DruidDataSource();
//        
//        dataSource.setUrl("jdbc:mysql://ip:3306/test?" + mysqlProperties);
//        dataSource.setUsername("name");
//        dataSource.setPassword("password");
//        
//        dataSource.init();
//        Connection connection = dataSource.getConnection();
//        PreparedStatement preparedStatement = connection.prepareStatement("insert into Test (name,gmt_created,gmt_modified) values (?,now(),now())");
//
//        for (int i = 0; i < insertCount; i++) {
//            preparedStatement.setString(1, i+" ");
//            preparedStatement.addBatch();
//            if((i+1) % batchSize == 0) {
//                preparedStatement.executeBatch();
//            }
//        }
//        preparedStatement.executeBatch();
//        connection.close();   
//        dataSource.close();
//    }
//}
